﻿"use strict"

async function resetCardHeight(parent,child){
    await Helper.sleep(1000);

    var container = $(parent)
    for(var ii=0;ii<container.length;ii++){
        var mycard2 = $(container[ii]).find(child);
        var maxHeight = 0;
        for(var jj=0;jj<mycard2.length;jj++){
            var outerHeight = $(mycard2[jj]).outerHeight();
            maxHeight = outerHeight > maxHeight ? outerHeight:maxHeight;
        }
        for(var jj=0;jj<mycard2.length;jj++){
            if($(mycard2[jj]).outerHeight()!=maxHeight){
                $(mycard2[jj]).outerHeight(maxHeight);
            }
        }
    }
}

function onLogin()
{
    ShowRunes();
}

async function Countdown(){
    await Helper.sleep(3000);

    while(true){
        try{
            var value = await GetVOOKProgress();
            SetProgressBar(value + "%");
        }catch(e){}

        await Helper.sleep(10000);

    }
}

async function SetProgressBar(value)
{
    $(".progress-bar").outerWidth(value)
    $(".progress-value").html(value)

}

async function Refresh()
{
    Countdown();    
    ShowDataLayout()

}


let RunesAll  = null;
async function ShowRunes()
{
    $.ajax({
        url: Helper.GetServerIP() + "/RunesAll",
                  dataType: "text",
                  type: "post",
                  data: { address: Helper.addressCur, offset: 0,count: 12 },
                  success: function (data) {
                    
                        // 删除之前的数据
                        var runes_list = $(".runes-list")[0];
                        for (var i = runes_list.children.length - 1; i >= 0; i--) {
                            runes_list.children[i].remove();
                        }

                        RunesAll = JSON.parse(data);

                        for(var ii=0;ii<RunesAll.length;ii++)
                        {
                            var item = JSON.parse(RunesAll[ii]);
                            runes_insert( runes_list, item.Data, item.Number, item.ID, getDateDiff(item.Created), onclickitem);
                        }

                  },
                  error: function (err) {
                    ShowToastrError("Error",err.responseText);
                  }
      });

}

async function ShowDataLayout()
{
    $.ajax({
        url: Helper.GetServerIP() + "/DataLayout",
                  dataType: "text",
                  type: "post",
                  data: { tick: project_tick },
                  success: function (data) {
                    
                    var jsonData = JSON.parse(data);
                    $("#userCount").html(jsonData.userCount);
	    $("#LaunchpadDonate").html(Helper.Mul(jsonData.LaunchpadDonate,"10") );
                    $("#TotalTradingVolume").html(Helper.Mul(Helper.Mul(jsonData.LaunchpadDonate,"10"),"1000"));
                    // $("#LaunchpadDonate").html("$ "+ Helper.Mul(jsonData.LaunchpadDonate,"1.2") );
                    // $("#TotalTradingVolume").html("$ "+jsonData.TotalTradingVolume);

                  },
                  error: function (err) {
                    ShowToastrError("Error",err.responseText);
                  }
      });

}


(function($) {
    "use strict"

    // 对齐背景
    resetCardHeight(".container-fluid",".profile-statistics");
    resetCardHeight(".container-fluid",".profile-statistics2");

    jQuery(window).on('resize',function(){
        resetCardHeight(".container-fluid",".profile-statistics");
        resetCardHeight(".container-fluid",".profile-statistics2");
    });

    Refresh();

})(jQuery);


